/*     */ package com.zimbra.cs.redolog.op;
/*     */ 
/*     */ import com.zimbra.common.mailbox.Color;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.cs.mailbox.MailServiceException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.MailboxOperation;
/*     */ import com.zimbra.cs.redolog.RedoLogInput;
/*     */ import com.zimbra.cs.redolog.RedoLogOutput;
/*     */ import com.zimbra.cs.redolog.Version;
/*     */ import java.io.IOException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CreateSavedSearch
/*     */   extends RedoableOp
/*     */ {
/*     */   private int mSearchId;
/*     */   private String mUuid;
/*     */   private String mName;
/*     */   private String mQuery;
/*     */   private String mTypes;
/*     */   private String mSort;
/*     */   private int mFolderId;
/*     */   private int mFlags;
/*     */   private long mColor;
/*     */   
/*     */   public CreateSavedSearch()
/*     */   {
/*  46 */     super(MailboxOperation.CreateSavedSearch);
/*  47 */     this.mSearchId = 0;
/*     */   }
/*     */   
/*     */   public CreateSavedSearch(int mailboxId, int folderId, String name, String query, String types, String sort, int flags, Color color) {
/*  51 */     this();
/*  52 */     setMailboxId(mailboxId);
/*  53 */     this.mSearchId = 0;
/*  54 */     this.mName = (name != null ? name : "");
/*  55 */     this.mQuery = (query != null ? query : "");
/*  56 */     this.mTypes = (types != null ? types : "");
/*  57 */     this.mSort = (sort != null ? sort : "");
/*  58 */     this.mFolderId = folderId;
/*  59 */     this.mFlags = flags;
/*  60 */     this.mColor = color.getValue();
/*     */   }
/*     */   
/*     */   public int getSearchId() {
/*  64 */     return this.mSearchId;
/*     */   }
/*     */   
/*     */   public String getUuid() {
/*  68 */     return this.mUuid;
/*     */   }
/*     */   
/*     */   public void setSearchIdAndUuid(int searchId, String uuid) {
/*  72 */     this.mSearchId = searchId;
/*  73 */     this.mUuid = uuid;
/*     */   }
/*     */   
/*     */   protected String getPrintableData() {
/*  77 */     StringBuilder sb = new StringBuilder("id=").append(this.mSearchId);
/*  78 */     sb.append(", uuid=").append(this.mUuid);
/*  79 */     sb.append(", name=").append(this.mName).append(", query=").append(this.mQuery);
/*  80 */     sb.append(", types=").append(this.mTypes).append(", sort=").append(this.mSort);
/*  81 */     sb.append(", flags=").append(this.mFlags);
/*  82 */     sb.append(", color=").append(this.mColor);
/*  83 */     return sb.toString();
/*     */   }
/*     */   
/*     */   protected void serializeData(RedoLogOutput out) throws IOException {
/*  87 */     out.writeInt(this.mSearchId);
/*  88 */     if (getVersion().atLeast(1, 37)) {
/*  89 */       out.writeUTF(this.mUuid);
/*     */     }
/*  91 */     out.writeUTF(this.mName);
/*  92 */     out.writeUTF(this.mQuery);
/*  93 */     out.writeUTF(this.mTypes);
/*  94 */     out.writeUTF(this.mSort);
/*  95 */     out.writeInt(this.mFolderId);
/*  96 */     out.writeInt(this.mFlags);
/*     */     
/*  98 */     out.writeLong(this.mColor);
/*     */   }
/*     */   
/*     */   protected void deserializeData(RedoLogInput in) throws IOException {
/* 102 */     this.mSearchId = in.readInt();
/* 103 */     if (getVersion().atLeast(1, 37)) {
/* 104 */       this.mUuid = in.readUTF();
/*     */     }
/* 106 */     this.mName = in.readUTF();
/* 107 */     this.mQuery = in.readUTF();
/* 108 */     this.mTypes = in.readUTF();
/* 109 */     this.mSort = in.readUTF();
/* 110 */     this.mFolderId = in.readInt();
/* 111 */     this.mFlags = (getVersion().atLeast(1, 28) ? in.readInt() : 0);
/* 112 */     if (getVersion().atLeast(1, 27)) {
/* 113 */       this.mColor = in.readLong();
/*     */     } else
/* 115 */       this.mColor = in.readByte();
/*     */   }
/*     */   
/*     */   public void redo() throws Exception {
/* 119 */     int mboxId = getMailboxId();
/* 120 */     Mailbox mailbox = MailboxManager.getInstance().getMailboxById(mboxId);
/*     */     try
/*     */     {
/* 123 */       mailbox.createSearchFolder(getOperationContext(), this.mFolderId, this.mName, this.mQuery, this.mTypes, this.mSort, this.mFlags, Color.fromMetadata(this.mColor));
/*     */     }
/*     */     catch (MailServiceException e) {
/* 126 */       String code = e.getCode();
/* 127 */       if (code.equals("mail.ALREADY_EXISTS")) {
/* 128 */         if (mLog.isInfoEnabled())
/* 129 */           mLog.info("Search " + this.mSearchId + " already exists in mailbox " + mboxId);
/*     */       } else {
/* 131 */         throw e;
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/redolog/op/CreateSavedSearch.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */